﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Mobile.Configuration;

namespace ConfigurationGettingStarted
{
    class ConnectionStringCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ConnectionString();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            ConnectionString e = (ConnectionString)element;

            return e.Name;
        }

        public ConnectionString GetMenuItem(int id)
        {
            return (ConnectionString)BaseGet(id);
        }
    }

    class ConnectionString : ConfigurationElement
    {
        private const string AttributeName = "name";
        private const string AttributeConnectionString = "connectionString";
        private const string AttributeProvider = "providerName";

        [ConfigurationProperty(AttributeName)]
        public string Name
        {
            get { return (string)this[AttributeName]; }
            set { this[AttributeName] = value; }
        }

        [ConfigurationProperty(AttributeConnectionString)]
        public string Connection
        {
            get { return (string)this[AttributeConnectionString]; }
            set { this[AttributeConnectionString] = value; }
        }

        [ConfigurationProperty(AttributeProvider)]
        public string Provider
        {
            get { return (string)this[AttributeProvider]; }
            set { this[AttributeProvider] = value; }
        }
    }
}
